﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using com.vs.DataAccess;
using com.vs.General;

namespace com.vs.DataAccess.DO
{
    public partial class ShipmentHeaderDO : BaseDO
    {


        #region "Get Model"
        /// <summary>
        /// 将符合数据库主键的持久对象提取到模型对象中，如数据库符合条件的持久对象不存在，则返回空对象
        /// </summary>
        /// <remarks></remarks>
        public static ShipmentHeaderDO GetModelByPK(Session sess, double iIntShpNum)
        {
            DataHelper helper = null;
            DataTable dtModel = null;

            try
            {
                helper = new DataHelper(sess);
                dtModel = helper.GetTable(CommandType.Text, SelectSequel + " WHERE INTERNAL_SHIPMENT_NUM = @INTERNAL_SHIPMENT_NUM", new IDataParameter[]{
                    DataHelper.BuildParameter(sess, "@INTERNAL_SHIPMENT_NUM", iIntShpNum)
                });
                if (!DataManager.IsEmpty(dtModel))
                {
                    return GetModel(dtModel.Rows[0]);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                ExceptionManager.LogException(sess, e);
                return null;
            }
            finally
            {
                if (helper != null)
                    helper.Dispose();
            }

        }

        #endregion

        #region "DataBase Operation"
        /// <summary>
        /// 在数据库里创建该数据访问对象的持久化数据，同时自增长属性INTERNAL_SHIPMENT_NUM也会同时得到更新,并提供数据库事务支持
        /// </summary>
        /// <remarks></remarks>
        public string Insert(Session sess)
        {
            DataHelper helper = null;
            IDataParameter[] paras = null;
            string stSQL = "SHP_IShipmentHeader";
            try
            {
                helper = new DataHelper(sess);
                paras = ValueParas(this);
                return "" + helper.GetInt(CommandType.StoredProcedure, stSQL, paras);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (helper != null)
                    helper.Dispose();
            }

        }

        public void Delete(Session sess)
        {
            DataHelper helper = null;
            string stSQL = "DELETE FROM SHIPMENT_HEADER ";
            try
            {
                helper = new DataHelper(sess);
                helper.Update(CommandType.Text, stSQL + " WHERE INTERNAL_SHIPMENT_NUM = @INTERNAL_SHIPMENT_NUM", new IDataParameter[]{
                    DataHelper.BuildParameter(sess, "@INTERNAL_SHIPMENT_NUM", this.INTERNAL_SHIPMENT_NUM)
                });
            }
            catch (Exception e)
            {
                ExceptionManager.LogException(sess, e);
            }
            finally
            {
                if (helper != null)
                    helper.Dispose();
            }


        }

        /// <summary>
        /// 将该数据访问对象的变化同步到数据库中，如果该数据访问对象在数据库中的持久数据不存在，同步不会发生，同时也不会抛出例外
        /// </summary>
        /// <remarks></remarks>
        public void Update(Session sess)
        {
            DataHelper helper = null;
            string stSQL = "SHP_UShipmentHeader";
            try
            {
                helper = new DataHelper(sess);
                helper.Update(CommandType.StoredProcedure, stSQL, ValueParas(this));
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (helper != null)
                    helper.Dispose();
            }

        }

        public string Update(Session sess, Dictionary<string, object> dcData)
        {
            DataHelper helper = null;
            StringBuilder sbSQL = null;
            string stSQL = null;
            int i = 0;
            IDataParameter[] paras = null;

            try
            {
                if (dcData.Count < 1)
                    return null;
                helper = new DataHelper(sess);
                sbSQL = new StringBuilder(256)
                            .Append(" UPDATE SHIPMENT_HEADER SET ");
                paras = new IDataParameter[dcData.Count + 1];
                foreach (KeyValuePair<string, object> kvp in dcData)
                {
                    sbSQL.Append(kvp.Key).Append(" = @Value").Append(i).Append(",");
                    paras[i] = new SqlParameter("@Value" + i, kvp.Value);
                    i++;
                }

                stSQL = sbSQL.ToString();
                stSQL = stSQL.Substring(0, stSQL.Length - 1);

                stSQL = stSQL + " WHERE INTERNAL_SHIPMENT_NUM = @INTERNAL_SHIPMENT_NUM";
                paras[i] = new SqlParameter("@INTERNAL_SHIPMENT_NUM", this.INTERNAL_SHIPMENT_NUM);

                helper.Update(CommandType.Text, stSQL, paras);

                return null;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (helper != null)
                    helper.Dispose();
            }
        }
        #endregion

        #region "Data Load"
        /// <summary>
        /// 装载对象SHIPMENHEADER的所有持久性对象到集合，如果数据量大，调用此方法会造成性能上的问题，请谨慎使用
        /// </summary>
        /// <remarks></remarks>
        public static List<ShipmentHeaderDO> GetAll(Session sess)
        {
            DataHelper helper = null;
            DataTable dtModel = null;
            string stSQL = "SP_SHIPMENHEADER_SelectAll";
            try
            {
                helper = new DataHelper(sess);
                dtModel = helper.GetTable(CommandType.StoredProcedure, stSQL);
                return LoadListFromDataView(dtModel.DefaultView);
            }
            catch (Exception e)
            {
                ExceptionManager.LogException(sess, e);
                return null;
            }
            finally
            {
                if (helper != null)
                    helper.Dispose();
            }

        }


        /// <summary>
        /// 装载指定列的值等于指定值的的所有持久性SHIPMENHEADER对象到集合
        /// </summary>
        /// <remarks></remarks>
        public static DataTable GetTableByColumn(Session sess, string columnName, Object value)
        {
            DataHelper helper = null;
            IDataParameter[] paras = null;
            string stSQL = null;

            try
            {
                helper = new DataHelper(sess);
                stSQL = SelectSequel + " Where [" + columnName + "] =@Value ";
                paras = new IDataParameter[]{
			                new SqlParameter( "@Value", value)
		                };
                return helper.GetTable(CommandType.Text, stSQL, paras);
            }
            catch (Exception e)
            {
                ExceptionManager.LogException(sess, e);
                return null;
            }
            finally
            {
                if (helper != null)
                    helper.Dispose();
            }
        }

        public static List<ShipmentHeaderDO> GetListByColumn(Session sess, string columnName, Object value)
        {
            DataTable dtModel = null;

            try
            {
                dtModel = GetTableByColumn(sess, columnName, value);
                return LoadListFromDataView(dtModel.DefaultView);
            }
            catch (Exception e)
            {
                ExceptionManager.LogException(sess, e);
                return null;
            }
            finally
            {
            }
        }


        /// <summary>
        /// 从DataView装载持久性SHIPMENHEADER对象到集合
        /// </summary>
        /// <remarks></remarks>
        private static List<ShipmentHeaderDO> LoadListFromDataView(DataView dv)
        {
            List<ShipmentHeaderDO> list = new List<ShipmentHeaderDO>();
            for (int index = 0; index <= dv.Count - 1; index++)
            {
                list.Add(GetModel(dv[index].Row));
            }
            return list;
        }

        /// <summary>
        /// loading data value  to property from Datarow
        /// </summary>
        /// <remarks></remarks>
        private static ShipmentHeaderDO GetModel(DataRow row)
        {
            ShipmentHeaderDO shpHdrDO = new ShipmentHeaderDO();
            if (!row["INTERNAL_SHIPMENT_NUM"].Equals(DBNull.Value)) shpHdrDO.INTERNAL_SHIPMENT_NUM = Convert.ToInt32(row["INTERNAL_SHIPMENT_NUM"]);
            if (!row["WAREHOUSE"].Equals(DBNull.Value)) shpHdrDO.WAREHOUSE = Convert.ToString(row["WAREHOUSE"]);
            if (!row["INTERNAL_LOAD_NUM"].Equals(DBNull.Value)) shpHdrDO.INTERNAL_LOAD_NUM = Convert.ToInt32(row["INTERNAL_LOAD_NUM"]);
            if (!row["SHIPMENT_ID"].Equals(DBNull.Value)) shpHdrDO.SHIPMENT_ID = Convert.ToString(row["SHIPMENT_ID"]);
            if (!row["LEADING_STS"].Equals(DBNull.Value)) shpHdrDO.LEADING_STS = Convert.ToInt32(row["LEADING_STS"]);
            if (!row["SHIPMENT_TYPE"].Equals(DBNull.Value)) shpHdrDO.SHIPMENT_TYPE = Convert.ToString(row["SHIPMENT_TYPE"]);
            if (!row["COMPANY"].Equals(DBNull.Value)) shpHdrDO.COMPANY = Convert.ToString(row["COMPANY"]);
            if (!row["ROUTE"].Equals(DBNull.Value)) shpHdrDO.ROUTE = Convert.ToString(row["ROUTE"]);
            if (!row["SHIP_TO"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO = Convert.ToString(row["SHIP_TO"]);
            if (!row["SHIP_TO_ADDRESS1"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_ADDRESS1 = Convert.ToString(row["SHIP_TO_ADDRESS1"]);
            if (!row["SHIP_TO_ADDRESS2"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_ADDRESS2 = Convert.ToString(row["SHIP_TO_ADDRESS2"]);
            if (!row["SHIP_TO_CITY"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_CITY = Convert.ToString(row["SHIP_TO_CITY"]);
            if (!row["SHIP_TO_STATE"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_STATE = Convert.ToString(row["SHIP_TO_STATE"]);
            if (!row["SHIP_TO_COUNTRY"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_COUNTRY = Convert.ToString(row["SHIP_TO_COUNTRY"]);
            if (!row["SHIP_TO_POSTAL_CODE"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_POSTAL_CODE = Convert.ToString(row["SHIP_TO_POSTAL_CODE"]);
            if (!row["SHIP_TO_PHONE_NUM"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_PHONE_NUM = Convert.ToString(row["SHIP_TO_PHONE_NUM"]);
            if (!row["SHIP_TO_FAX_NUM"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_FAX_NUM = Convert.ToString(row["SHIP_TO_FAX_NUM"]);
            if (!row["PRIORITY"].Equals(DBNull.Value)) shpHdrDO.PRIORITY = Convert.ToInt32(row["PRIORITY"]);
            if (!row["USER_STAMP"].Equals(DBNull.Value)) shpHdrDO.USER_STAMP = Convert.ToString(row["USER_STAMP"]);
            if (!row["DATE_TIME_STAMP"].Equals(DBNull.Value)) shpHdrDO.DATE_TIME_STAMP = Convert.ToDateTime(row["DATE_TIME_STAMP"]);
            if (!row["SHIP_TO_NAME"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_NAME = Convert.ToString(row["SHIP_TO_NAME"]);
            if (!row["SHIP_TO_ATTENTION_TO"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_ATTENTION_TO = Convert.ToString(row["SHIP_TO_ATTENTION_TO"]);
            if (!row["SHIP_TO_EMAIL_ADDRESS"].Equals(DBNull.Value)) shpHdrDO.SHIP_TO_EMAIL_ADDRESS = Convert.ToString(row["SHIP_TO_EMAIL_ADDRESS"]);
            if (!row["REQUESTED_DELIVERY_DATE"].Equals(DBNull.Value)) shpHdrDO.REQUESTED_DELIVERY_DATE = Convert.ToDateTime(row["REQUESTED_DELIVERY_DATE"]);
            if (!row["REQUESTED_DELIVERY_TYPE"].Equals(DBNull.Value)) shpHdrDO.REQUESTED_DELIVERY_TYPE = Convert.ToString(row["REQUESTED_DELIVERY_TYPE"]);
            if (!row["DELIVERY_NOTE"].Equals(DBNull.Value)) shpHdrDO.DELIVERY_NOTE = Convert.ToString(row["DELIVERY_NOTE"]);
            if (!row["SCHEDULED_SHIP_DATE"].Equals(DBNull.Value)) shpHdrDO.SCHEDULED_SHIP_DATE = Convert.ToDateTime(row["SCHEDULED_SHIP_DATE"]);
            if (!row["ACTUAL_SHIP_DATE_TIME"].Equals(DBNull.Value)) shpHdrDO.ACTUAL_SHIP_DATE_TIME = Convert.ToDateTime(row["ACTUAL_SHIP_DATE_TIME"]);
            if (!row["ACTUAL_DELIVERY_DATE_TIME"].Equals(DBNull.Value)) shpHdrDO.ACTUAL_DELIVERY_DATE_TIME = Convert.ToDateTime(row["ACTUAL_DELIVERY_DATE_TIME"]);
            if (!row["ERP_ORDER"].Equals(DBNull.Value)) shpHdrDO.ERP_ORDER = Convert.ToString(row["ERP_ORDER"]);
            if (!row["INTERNAL_WAVE_NUM"].Equals(DBNull.Value)) shpHdrDO.INTERNAL_WAVE_NUM = Convert.ToInt32(row["INTERNAL_WAVE_NUM"]);
            if (!row["REJECTION_NOTE"].Equals(DBNull.Value)) shpHdrDO.REJECTION_NOTE = Convert.ToString(row["REJECTION_NOTE"]);
            if (!row["TRAILING_STS"].Equals(DBNull.Value)) shpHdrDO.TRAILING_STS = Convert.ToInt32(row["TRAILING_STS"]);
            if (!row["SHIP_DOCK"].Equals(DBNull.Value)) shpHdrDO.SHIP_DOCK = Convert.ToString(row["SHIP_DOCK"]);
            if (!row["ALLOCATE_COMPLETE"].Equals(DBNull.Value)) shpHdrDO.ALLOCATE_COMPLETE = Convert.ToString(row["ALLOCATE_COMPLETE"]);
            return shpHdrDO;
        }

        #endregion

        #region "Other function"
        /// <summary>
        /// 该数据访问对象从数据库中提取数据的Sql语句 
        /// </summary>
        /// <remarks></remarks>
        private static string SelectSequel
        {
            get
            {
                return "Select * From [SHIPMENT_HEADER] ";
            }
        }

        /// <summary>
        /// 该数据访问对象的属性值装载到数据库更新参数数组
        /// </summary>
        /// <remarks></remarks>
        private static IDbDataParameter[] ValueParas(ShipmentHeaderDO shpHdrDO)
        {
            SqlParameter[] paras = new SqlParameter[35];
            paras[0] = new SqlParameter("@INTERNAL_SHIPMENT_NUM", shpHdrDO.INTERNAL_SHIPMENT_NUM);
            paras[1] = new SqlParameter("@WAREHOUSE", shpHdrDO.WAREHOUSE == String.Empty ? DBNull.Value : (object)shpHdrDO.WAREHOUSE);
            paras[2] = new SqlParameter("@INTERNAL_LOAD_NUM", shpHdrDO.INTERNAL_LOAD_NUM);
            paras[3] = new SqlParameter("@SHIPMENT_ID", shpHdrDO.SHIPMENT_ID == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIPMENT_ID);
            paras[4] = new SqlParameter("@LEADING_STS", shpHdrDO.LEADING_STS);
            paras[5] = new SqlParameter("@SHIPMENT_TYPE", shpHdrDO.SHIPMENT_TYPE == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIPMENT_TYPE);
            paras[6] = new SqlParameter("@COMPANY", shpHdrDO.COMPANY == String.Empty ? DBNull.Value : (object)shpHdrDO.COMPANY);
            paras[7] = new SqlParameter("@ROUTE", shpHdrDO.ROUTE == String.Empty ? DBNull.Value : (object)shpHdrDO.ROUTE);
            paras[8] = new SqlParameter("@SHIP_TO", shpHdrDO.SHIP_TO == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO);
            paras[9] = new SqlParameter("@SHIP_TO_ADDRESS1", shpHdrDO.SHIP_TO_ADDRESS1 == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_ADDRESS1);
            paras[10] = new SqlParameter("@SHIP_TO_ADDRESS2", shpHdrDO.SHIP_TO_ADDRESS2 == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_ADDRESS2);
            paras[11] = new SqlParameter("@SHIP_TO_CITY", shpHdrDO.SHIP_TO_CITY == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_CITY);
            paras[12] = new SqlParameter("@SHIP_TO_STATE", shpHdrDO.SHIP_TO_STATE == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_STATE);
            paras[13] = new SqlParameter("@SHIP_TO_COUNTRY", shpHdrDO.SHIP_TO_COUNTRY == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_COUNTRY);
            paras[14] = new SqlParameter("@SHIP_TO_POSTAL_CODE", shpHdrDO.SHIP_TO_POSTAL_CODE == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_POSTAL_CODE);
            paras[15] = new SqlParameter("@SHIP_TO_PHONE_NUM", shpHdrDO.SHIP_TO_PHONE_NUM == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_PHONE_NUM);
            paras[16] = new SqlParameter("@SHIP_TO_FAX_NUM", shpHdrDO.SHIP_TO_FAX_NUM == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_FAX_NUM);
            paras[17] = new SqlParameter("@PRIORITY", shpHdrDO.PRIORITY);
            paras[18] = new SqlParameter("@USER_STAMP", shpHdrDO.USER_STAMP == String.Empty ? DBNull.Value : (object)shpHdrDO.USER_STAMP);
            paras[19] = new SqlParameter("@DATE_TIME_STAMP", System.DateTime.Now);
            paras[20] = new SqlParameter("@SHIP_TO_NAME", shpHdrDO.SHIP_TO_NAME == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_NAME);
            paras[21] = new SqlParameter("@SHIP_TO_ATTENTION_TO", shpHdrDO.SHIP_TO_ATTENTION_TO == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_ATTENTION_TO);
            paras[22] = new SqlParameter("@SHIP_TO_EMAIL_ADDRESS", shpHdrDO.SHIP_TO_EMAIL_ADDRESS == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_TO_EMAIL_ADDRESS);
            paras[23] = new SqlParameter("@REQUESTED_DELIVERY_DATE", shpHdrDO.REQUESTED_DELIVERY_DATE == DateTime.MinValue ? DBNull.Value : (object)shpHdrDO.REQUESTED_DELIVERY_DATE);
            paras[24] = new SqlParameter("@REQUESTED_DELIVERY_TYPE", shpHdrDO.REQUESTED_DELIVERY_TYPE == String.Empty ? DBNull.Value : (object)shpHdrDO.REQUESTED_DELIVERY_TYPE);
            paras[25] = new SqlParameter("@DELIVERY_NOTE", shpHdrDO.DELIVERY_NOTE == String.Empty ? DBNull.Value : (object)shpHdrDO.DELIVERY_NOTE);
            paras[26] = new SqlParameter("@SCHEDULED_SHIP_DATE", shpHdrDO.SCHEDULED_SHIP_DATE == DateTime.MinValue ? DBNull.Value : (object)shpHdrDO.SCHEDULED_SHIP_DATE);
            paras[27] = new SqlParameter("@ACTUAL_SHIP_DATE_TIME", shpHdrDO.ACTUAL_SHIP_DATE_TIME == DateTime.MinValue ? DBNull.Value : (object)shpHdrDO.ACTUAL_SHIP_DATE_TIME);
            paras[28] = new SqlParameter("@ACTUAL_DELIVERY_DATE_TIME", shpHdrDO.ACTUAL_DELIVERY_DATE_TIME == DateTime.MinValue ? DBNull.Value : (object)shpHdrDO.ACTUAL_DELIVERY_DATE_TIME);
            paras[29] = new SqlParameter("@ERP_ORDER", shpHdrDO.ERP_ORDER == String.Empty ? DBNull.Value : (object)shpHdrDO.ERP_ORDER);
            paras[30] = new SqlParameter("@INTERNAL_WAVE_NUM", shpHdrDO.INTERNAL_WAVE_NUM);
            paras[31] = new SqlParameter("@REJECTION_NOTE", shpHdrDO.REJECTION_NOTE == String.Empty ? DBNull.Value : (object)shpHdrDO.REJECTION_NOTE);
            paras[32] = new SqlParameter("@TRAILING_STS", shpHdrDO.TRAILING_STS);
            paras[33] = new SqlParameter("@SHIP_DOCK", shpHdrDO.SHIP_DOCK == String.Empty ? DBNull.Value : (object)shpHdrDO.SHIP_DOCK);
            paras[34] = new SqlParameter("@ALLOCATE_COMPLETE", shpHdrDO.ALLOCATE_COMPLETE == String.Empty ? DBNull.Value : (object)shpHdrDO.ALLOCATE_COMPLETE);


            paras[0].DbType = DbType.Decimal;
            paras[1].DbType = DbType.String;
            paras[2].DbType = DbType.Decimal;
            paras[3].DbType = DbType.String;
            paras[4].DbType = DbType.Decimal;
            paras[5].DbType = DbType.String;
            paras[6].DbType = DbType.String;
            paras[7].DbType = DbType.String;
            paras[8].DbType = DbType.String;
            paras[9].DbType = DbType.String;
            paras[10].DbType = DbType.String;
            paras[11].DbType = DbType.String;
            paras[12].DbType = DbType.String;
            paras[13].DbType = DbType.String;
            paras[14].DbType = DbType.String;
            paras[15].DbType = DbType.String;
            paras[16].DbType = DbType.String;
            paras[17].DbType = DbType.Decimal;
            paras[18].DbType = DbType.String;
            paras[19].DbType = DbType.DateTime;
            paras[20].DbType = DbType.String;
            paras[21].DbType = DbType.String;
            paras[22].DbType = DbType.String;
            paras[23].DbType = DbType.Date;
            paras[24].DbType = DbType.String;
            paras[25].DbType = DbType.String;
            paras[26].DbType = DbType.Date;
            paras[27].DbType = DbType.Date;
            paras[28].DbType = DbType.Date;
            paras[29].DbType = DbType.String;
            paras[30].DbType = DbType.Decimal;
            paras[31].DbType = DbType.String;
            paras[32].DbType = DbType.Decimal;
            paras[33].DbType = DbType.String;
            paras[34].DbType = DbType.String;

            return paras;
        }

        private static IDbDataParameter[] UpdateWherePara(ShipmentHeaderDO shpHdrDO)
        {
            SqlParameter[] paras = new SqlParameter[1];
            paras[0] = new SqlParameter("@INTERNAL_SHIPMENT_NUM", shpHdrDO.INTERNAL_SHIPMENT_NUM);
            return paras;
        }

        #endregion


        public static List<ShipmentHeaderDO> GetListByColumns(Session sess, List<KeyValuePair<string, KeyValuePair<string, object>>> dcParam, string stOrderBy)
        {
            DataTable dtModel = null;

            try
            {
                dtModel = GetTableByColumns(sess, dcParam, stOrderBy);
                return LoadListFromDataView(dtModel.DefaultView);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
            }
        }

        public static DataTable GetTableByColumns(Session sess, List<KeyValuePair<string, KeyValuePair<string, object>>> dcParam, string stOrderBy)
        {
            DataHelper helper = null;
            StringBuilder sbSQL = null;
            int i = 0;
            IDataParameter[] pars = null;

            try
            {
                helper = new DataHelper(sess);
                sbSQL = new StringBuilder(SelectSequel)
                    .Append(" WHERE 1=1 ");

                pars = new IDataParameter[dcParam.Count];
                foreach (KeyValuePair<string, KeyValuePair<string, object>> de in dcParam)
                {
                    sbSQL.Append(" AND ").Append(de.Key.ToString()).Append(de.Value.Key).Append("@Value").Append(i);
                    pars[i] = new SqlParameter("@Value" + i, de.Value.Value);
                    i++;
                }

                if (!StringManager.IsEmpty(stOrderBy))
                {
                    sbSQL.Append(stOrderBy);
                }
                return helper.GetTable(CommandType.Text, sbSQL.ToString(), pars);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (helper != null)
                    helper.Dispose();
            }
        }
    }
}
